home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0192.ARJ / CB386.C < prev    next >
C/C++ Source or Header  |  1991-09-04  |  4KB  |  191 lines

  1. /****************************************************************
  2.  *                                                              *
  3.  * CB386.C - main file for CopyBuilder 386                      *
  4.  * See makefile for compile directives                          *
  5.  * Al Williams -- August 1991                                   *
  6.  *                                                              *
  7.  ****************************************************************/
  8. #include <stdio.h>
  9. #include <dos.h>
  10. #include <ctype.h>
  11. #include "cb386.h"
  12. #include "display.h"
  13.  
  14. /* current drive number */
  15. int driveno;
  16.  
  17. /* current bios parameter block */
  18. struct _bpb bpb;
  19.  
  20. /* size of disk */
  21. unsigned disksize;
  22.  
  23. /* information about buffer */
  24. struct _bufinfo bufinfo;
  25.  
  26.  
  27. /* number of sectors */
  28. unsigned sectorct;
  29.  
  30. /* storage for disk image */
  31. unsigned char *diskbuf;
  32.  
  33. /* set when a critical error occurs */
  34. int critical_err;
  35.  
  36. /* DOS buffer for disk BIOS reads and writes */
  37. char *dosbuf;
  38.  
  39. /* text of format command */
  40. char fmtcmd[129];
  41.  
  42. /* set when a critical error occurs */
  43. int critical_err;
  44.  
  45. /* critical error messages */
  46. static char *cmsgs[]=
  47.   {
  48.   "Write protect",
  49.   "Unknown unit",
  50.   "Drive not ready",
  51.   "Unknown command",
  52.   "CRC error",
  53.   "Bad Request",
  54.   "Seek error",
  55.   "Unknown media",
  56.   "Sector not found",
  57.   "Out of paper",
  58.   "Write error",
  59.   "Read error",
  60.   "General failure",
  61.   "Unknown",
  62.   "Unknown",
  63.   "Invalid change"
  64.   };
  65.  
  66.  
  67. /* Critical error handler */
  68. void cerror(int dev,int code)
  69.   {
  70.   char msg[81];
  71.   int choice;
  72.   critical_err=code&=0xFF;
  73.   sprintf(msg,"Critical error: %s (Retry, Fail, Ignore)",
  74.           cmsgs[code]);
  75.   choice=prompt(msg,"RIF",ERRCOLOR);
  76.   if (choice==0) choice=_HARDERR_RETRY;
  77.   else if (choice==1) choice=_HARDERR_IGNORE;
  78.   else choice=_HARDERR_FAIL;  /* F or ESC */
  79.   _hardresume(choice);
  80.   }
  81.  
  82. /* Keyboard handler -- don't allow ^ALT-DEL */
  83.  
  84.  
  85.  
  86.  
  87. /* main program */
  88. main(int argc,char *argv[])
  89.   {
  90. /* set up critical error handler */
  91.   _harderr(cerror);
  92.   if (argc>2||argv[1][0]=='?'||argv[1][1]=='?')
  93.     error("CopyBuilder 386 by Al Williams\n"
  94.           "A diskette duplication system\n"
  95.           "Usage: CB386 [drive]\n");
  96. /* save current drive/directory */
  97.   cdsave();
  98. /* set up video mode and detect monitor type */
  99.   vidmode();
  100. /* if mono monitor, set up neutral colors */
  101.   if (mono)
  102.     {
  103.     TEXTCOLOR=7;
  104.     SOCOLOR=0x70;
  105.     ERRCOLOR=1;
  106.     HELPCOLOR=7;
  107.     }
  108. /* reset title, etc. */
  109.   strcpy(bufinfo.title,"<EMPTY>");
  110.   strcpy(bufinfo.source,"N/A");
  111.   strcpy(fmtcmd,"format");
  112.   noreboot();
  113. /* if user asked for a disk on the command line, read it */
  114.   if (argc==2)
  115.     {
  116. /* show a display */
  117.     disp();
  118. /* read the disk */
  119.     read_disk(*argv[1]);
  120.     }
  121. /* goto main menu */
  122.   menu();
  123.   }
  124.  
  125.  
  126.  
  127. /* Non-interactive error routine */
  128. error(char *s)
  129.   {
  130.   printf("\n%s\n",s);
  131.   cdrestore();
  132.   exit(1);
  133.   }
  134.  
  135.  
  136. /* compute checksum
  137.    add sixteen bit words and wrap carry around */
  138. checksum()
  139.   {
  140.   unsigned char *bufp=diskbuf;
  141.   int i=bufinfo.size;
  142.   unsigned short cksum=0;
  143.   unsigned cksum1;
  144.   while (i--)
  145.     {
  146.     cksum1=cksum;
  147.     cksum1+=*bufp++;
  148.     cksum=cksum1&0xFFFF;
  149.     if (cksum1&0xFFFF0000)
  150.       cksum++;
  151.     }
  152.   bufinfo.ccsum=cksum;
  153.   return cksum;
  154.   }
  155.  
  156.  
  157. /* Format a disk in the indicated drive */
  158. format(int driveno)
  159.   {
  160.   char fcmd[80];
  161.   int stat;
  162. /* build command line */
  163.   sprintf(fcmd,"%s %c:",fmtcmd,driveno+'A');
  164. /* save video */
  165.   vidsave();
  166. /* execute command */
  167.   stat=system(fcmd);
  168.   vidrestore();
  169.   if (stat==-1) advise("Unable to execute format program");
  170.   }
  171.  
  172. /* turn the blinking -wait- on at bottom of screen */
  173. wait_on()
  174.   {
  175.   int ocolor=color;
  176.   color=SOCOLOR|0x80;   /* make it blink */
  177.   goxy(0,24);
  178.   clreol();
  179.   goxy(37,24);
  180.   printfc("-WAIT-");
  181.   curshide();
  182.   color=ocolor;
  183.   }
  184.  
  185. /* turn the blinking -wait- off at bottom of screen */
  186. wait_off()
  187.   {
  188.   goxy(0,24);
  189.   clreol();
  190.   }
  191.